﻿// ===================================
// <copyright>
// This file is part of LABSMFController.
//
//    LABSMFController is free software: you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation, either version 3 of the License, or
//    (at your option) any later version.
//
//    LABSMFController is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with LABSMFController.  If not, see <http://www.gnu.org/licenses/>.
//    Copyright 2011 David Bakker
//
//</copyright>
// <author>David Bakker</author>
// <email>mailto:DavidFBakker@gmail.com</email>
// <created>Sunday, May 08, 2011</created>
// <lastedit>Sunday, May 08, 2011</lastedit>
// ===================================

using LABSMFController.LABS.Devices;

namespace LABSMFController.LABS.Classses
{
    public static class LiquidMovementUtil
    {
        static LiquidMovementUtil()
        {
            if (LiquidMovements == null)
                InitWaterMovements();
        }

        public static int MAXSteps
        {
            get { return 10; }
        }

        public static LiquidMovementClass[] LiquidMovements { get; set; }

        private static void InitWaterMovements()
        {
            LiquidMovements = new LiquidMovementClass[MAXSteps];

            LiquidMovements[LiquidMovementOptions.SourceHLTDestinationMLT] =
                new LiquidMovementClass("Source HLT, Destination MLT")
                    {
                        PumpNumber = Settings.PUMPRight,
                        SourceBubblerID = Location.HLT,
                        DestinationBubblerID = Location.MLT,
                        LiquidMovementSourceToMonitor = LiquidMovementToMonitorSourceENUM.Source
                    };
            LiquidMovements[LiquidMovementOptions.SourceHLTDestinationMLT].AddVValve(
                VValveDevices.VValves[VVariableENUM.ThreeWay_3_2], ValveState.Open);
            LiquidMovements[LiquidMovementOptions.SourceHLTDestinationMLT].AddVValve(
                VValveDevices.VValves[VVariableENUM.ThreeWay_3_1],
                VValveDevices.VValves[VVariableENUM.ThreeWay_3_1].BSwing);
        }

        public static LiquidMovementClass GetLiquidMovementClass(int movementsENUM)
        {
            for (int c = 0; c < MAXSteps; c++)
            {
                if (LiquidMovements[movementsENUM] != null)
                {
                    return LiquidMovements[movementsENUM];
                }
            }
            return null;
        }
    }


    public class LiquidMovementClass
    {
        public LiquidMovementClass()
        {
        }

        public LiquidMovementClass(string description)
        {
            Description = description;
            IsActive = false;

            SourceBubblerID = -1;
            SourceBubblerGallonsToMove = 0;
            DestinationBubblerID = -1;
            DestinationBubblerGallons = 0;
            Rate = 0;

            ValveCount = 0;
            VValveCount = 0;

            Valves = new ValveDevice[ValveDevices.MAXValves];
            VValveLevel = new int[VValveDevices.MAXVValves];
            VValves = new VariableValveDevice[VValveDevices.MAXVValves];
        }

        public LiquidMovementDesitnationMethodENUM LiquidMovementDesitnationMethod { get; set; }
        public bool IsActive { get; set; }

        public string Description { get; private set; }

        public LiquidMovementToMonitorSourceENUM LiquidMovementSourceToMonitor { get; set; }

        public int SourceBubblerID { get; set; }
        public double SourceBubblerGallonsToMove { get; set; }
        public int DestinationBubblerID { get; set; }
        public double DestinationBubblerGallons { get; set; }

        public double Rate { get; set; }
        public double DurationToRun { get; set; }

        public ValveDevice[] Valves { get; private set; }
        public VariableValveDevice[] VValves { get; private set; }
        public int[] VValveLevel { get; private set; }
        public int ValveCount { get; private set; }
        public int VValveCount { get; private set; }

        public int PumpNumber { get; set; }


        public void AddVValve(VariableValveDevice vvalveDevice, int level)
        {
            VValveLevel[VValveCount] = level;
            VValves[VValveCount++] = vvalveDevice;
        }

        public void AddValve(ValveDevice valveDevice)
        {
            Valves[ValveCount++] = valveDevice;
        }
    }
}